class LocalStorageWithExpiry {
    
    // 支持小时单位
    static setItem(key:string, value:any, expiry:number, unit = 'minutes') {
        const now = new Date();
        let expiryMs;
        
        switch(unit) {
            case 'minutes':
                expiryMs = expiry * 60 * 1000;
                break;
            case 'hours':
                expiryMs = expiry * 60 * 60 * 1000;
                break;
            case 'days':
                expiryMs = expiry * 24 * 60 * 60 * 1000;
                break;
            default:
                expiryMs = expiry * 60 * 1000; // 默认分钟
        }
        
        const item = {
            value: value,
            expiry: now.getTime() + expiryMs,
            timestamp: now.toISOString()
        };
        localStorage.setItem(key, JSON.stringify(item));
    }
    
    // 其他方法保持不变...
    static getItem(key: string) {
        const itemStr = localStorage.getItem(key);
        if (!itemStr) return null;
        
        const item = JSON.parse(JSON.stringify(itemStr));
        const now = new Date();
        
        if (now.getTime() > item.expiry) {
            localStorage.removeItem(key);
            return null;
        }
        
        return item.value;
    }
}

export default LocalStorageWithExpiry